﻿
#include "iot_gpio_ex.h"
#include <stdio.h>     
#include "ohos_init.h" 
#include "cmsis_os2.h" 
#include "iot_gpio.h"  
#include "../inc/mpu6050.h"  
#include "../inc/duoji.h" 
#include "../inc/oled_demo_chinese.h"

extern void Rotate60Degrees(void);
extern void Rotate120Degrees(void);

extern MPU6050_Data_t sensor_data;


void ControlServoBasedOnSensorData(void) {
    MPU6050_GetData(&sensor_data);

    float speed = sqrt(sensor_data.gyro.x * sensor_data.gyro.x + sensor_data.gyro.y * sensor_data.gyro.y + sensor_data.gyro.z * sensor_data.gyro.z);
    if (speed > 1.0f) {
        Rotate60Degrees();
    }

    float acceleration = sqrt(sensor_data.accel.x * sensor_data.accel.x + sensor_data.accel.y * sensor_data.accel.y + sensor_data.accel.z * sensor_data.accel.z);
    if (acceleration > 2.0f) {
        Rotate120Degrees();
    }
}